package com.siloam.vo;

import java.util.List;

import com.siloam.module.Group;
import com.siloam.module.GroupUser;

public class GroupVO {
	
	private int id;
	private String name;
	private String leader;
	private String members;
	private String type;
	private String opt;
	
	public GroupVO(Group group) {
		setId(group.getId());
		setName(group.getName());
		setLeader(group.getGroupUsers() );
		setMember(group.getGroupUsers() );
		setType(group.getTypeText() );
		setOpt();
	}
	
	public void setOpt(){
		opt = "<a href='javascript:;' onclick='memberManager(" + id + 
			  ")'><img src='../../img/users.png' title='组员管理' alt='组员管理' /></a>";
	}

	public void setLeader(List<GroupUser> groupUsers){
		StringBuffer sb = new StringBuffer();
		for(GroupUser gu : groupUsers){
			if(gu.isLeader()){
				sb.append(gu.getUser().getName()).append(",");
			}
		}
		if(sb.length() > 0){
			sb.setLength(sb.length() - 1);
		}
		leader = sb.toString();	
	}
	
	public void setMember(List<GroupUser> groupUsers){
		StringBuffer sb = new StringBuffer();
		for(GroupUser gu : groupUsers){
			if(gu.isMember()){
				sb.append(gu.getUser().getName()).append(",");
			}
		}
		if(sb.length() > 0){
			sb.setLength(sb.length() - 1);
		}
		members = sb.toString();
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getLeader() {
		return leader;
	}
	public void setLeader(String leader) {
		this.leader = leader;
	}
	public String getMembers() {
		return members;
	}
	public void setMembers(String members) {
		this.members = members;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	public String getOpt() {
		return opt;
	}

	public void setOpt(String opt) {
		this.opt = opt;
	}
	
}
